package com.mhc.haval.security.util;

import com.mhc.haval.security.model.User;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @Author: zhenmo
 * @Description:
 * @Date: 17/10/22 13:42
 */
public class SessionUtil {

    public static User getUserInfo() {
        Object principal = SecurityContextHolder.getContext()
                .getAuthentication().getPrincipal();

        if (principal instanceof UserDetails) {
            return (User) principal;
        }

        return null;
    }
}
